package com.snake.springboot.authority.web.controller;

import com.snake.springboot.authority.api.model.AccountInfoModel;
import com.snake.springboot.authority.api.model.RequestUrlModel;
import com.snake.springboot.authority.api.service.AuthUsedService;
import io.swagger.annotations.ApiOperation;
import org.snake.common.result.ResponseResult;
import org.snake.common.result.ResponseResultFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 类 {@code AuthUsedController}  <br> .
 * <p>权限使用
 * 创建时间：2025/1/3 17:19
 * @author yxt
 * @see
 */
@RestController
@RequestMapping("auth/used")
public class AuthUsedController {
    @Resource
    private AuthUsedService authUsedService;

    @ApiOperation("权限码和路径")
    @PostMapping("/request_url_code")
    public ResponseResult<List<RequestUrlModel>> requestUrl(@RequestParam("whitelistFlag") Integer whitelistFlag){
        List<RequestUrlModel> list = authUsedService.requestUrl(whitelistFlag);
        return ResponseResultFactory.ucc("获取权限码和路径",list);
    }

    @ApiOperation("获取登录用户信息")
    @PostMapping("/account_auth")
    public ResponseResult<AccountInfoModel> accountAuth(
            @RequestParam(value = "type") Integer type,
            @RequestParam("accountId") String accountId
    ){
        AccountInfoModel info = authUsedService.accountAuth(type,accountId);
        return ResponseResultFactory.ucc("获取权限码和路径",info);
    }


    @ApiOperation("删除缓存")
    @PostMapping("/del_cache")
    public ResponseResult<AccountInfoModel> delCache(
            @RequestBody AccountInfoModel accountInfo
    ){
        authUsedService.delCache(accountInfo);
        return ResponseResultFactory.ucc("删除缓存");
    }

    @ApiOperation("刷新权限缓存")
    @PostMapping("/refresh_cache")
    public ResponseResult<Object> refreshRoleCache(){
        authUsedService.refreshRoleCache();
        return ResponseResultFactory.ucc("刷新缓存");
    }

}
